﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace WindowsFormsApplication1
{
    public partial class NuevoExpediente : Form
    {
        private int IdPaciente;
        private DateTime Fecha;
        Form previous;
        public NuevoExpediente(int IdPaciente, Form previous)
        {
            InitializeComponent();
            this.IdPaciente = IdPaciente;
            this.previous = previous;
            ///agregar nombre de paciente
            EmbeddedDatabase db = EmbeddedDatabase.Instance;
            SqlCeDataReader reader = db.GetDataReaderForCustomQuery("SELECT ApellidoPaterno, ApellidoMaterno,Nombre FROM [Paciente] WHERE IdPaciente=" + IdPaciente.ToString());
            reader.Read();
            String cNombre = reader.GetString(0) + " " + reader.GetString(1) + ", " + reader.GetString(2);
            lblNombrePaciente.Text = cNombre;

            ///agregar fecha
            Fecha = System.DateTime.Now;
            lblFecha.Text = Fecha.ToString();//Fecha.Day.ToString() + "/" + Fecha.Month.ToString() + "/" + Fecha.Year.ToString();

        }

        private void NuevoExpediente_Load(object sender, EventArgs e)
        {
            previous.Hide();
            this.Show();
        }

        private void btnAgregar_Click(object sender, EventArgs e)
        {
            EmbeddedDatabase db = EmbeddedDatabase.Instance;
            db.ExecuteNonQueryOperation("INSERT INTO [ExpedienteMedico] " +
                   "(idPaciente, ExploracionFisica, Topografia, Morfologia, Piel_y_anexos, Padecimiento, Antecedentes, Diagnostico, Tratamiento, Estudios, Fecha)" +
                   " VALUES (" +
                   "'" + IdPaciente + "'," +
                   "'" + txtExploracionFisica.Text + "'," +
                   "'" + txtTopografia.Text + "'," +
                   "'" + txtMorfologia.Text + "'," +
                   "'" + txtPielYAnexos.Text + "'," +
                   "'" + txtPadecimientoActual.Text + "'," +
                   "'" + txtAntecedentes.Text + "'," +
                   "'" + txtDiagnostico.Text + "'," +
                   "'" + txtTratamiento.Text + "'," +
                   "'" + txtEstudios.Text + "'," +
                   "'" + Fecha + "')");

            this.Hide();
            previous.Show();

        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Hide();
            previous.Show(); 
        }
    }
}
